<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/view/inc/sys.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${projectName}-编辑角色</title>
<jsp:include page="/WEB-INF/view/inc/css.jsp"></jsp:include>
</head>
<body class="cld-body">
	<div class="enter-panel ep-xs">
		<input type="hidden" id="roleId" value="${sysRole.roleId}">
  		<div class="form-group">
			<label for="name" class="col-sm-4">名称 <span class="text-danger">*</span></label>
			<div class="col-sm-8"><input type="text" class="form-control" id="name" placeholder="名称" value="${sysRole.name}"></div>
		</div>
		<hr/>
		<div class="list-panel">
			<c:forEach items="${sysMenuList}" var="item">
				<div class="panel panel-default item" style="margin-bottom: 10px;">
					<div class="panel-heading" style="padding: 5px 10px;"><label title="${item.name}" style="margin-bottom: 0px;font-size: 12px;"><input type="checkbox" name="roleResIds" value="${item.menuId}" onclick="info.resChange(this)" <c:if test="${item.ischeck == 1}">checked</c:if>/> ${item.name}</label></div>
					<div class="panel-body" style="padding: 10px 15px;">
						<c:forEach items="${item.cldMenus}" var="cldItem">
						<div>
							<label title="${cldItem.name}" style="margin-bottom: 0px;font-weight: normal;font-size: 12px;"><input type="checkbox" name="roleResIds" value="${cldItem.menuId}" <c:if test="${cldItem.ischeck == 1}">checked</c:if>/>
							${cldItem.name}<c:if test="${cldItem.type==1}">(功能)</c:if>
							</label>
							&nbsp;&nbsp;&nbsp;&nbsp;
							<c:forEach items="${cldItem.cldMenus}" var="cldItem2">
							&nbsp;&nbsp;<label title="${cldItem2.name}" style="margin-bottom: 0px;font-weight: normal;font-size: 12px;"><input type="checkbox" name="roleResIds" value="${cldItem2.menuId}" <c:if test="${cldItem2.ischeck == 1}">checked</c:if>/> ${cldItem2.name}</label>
							</c:forEach>
						</div>
						</c:forEach>
					</div>
				</div>
			</c:forEach>
		</div>
  		<div class="footer-operate">
			<span id="saveMsg" class="label label-danger"></span>
 			<div class="btn-group">
				<button type="button" id="saveBtn" class="btn btn-success enter-fn">保存</button>
			</div>
		</div>
	</div>

	<jsp:include page="/WEB-INF/view/inc/js.jsp"></jsp:include>
	<script type="text/javascript">
	var info = {
			resChange: function(_this) {
				var chk = $(_this);
				if(chk.prop('checked')) {
					//选中
					var chkList = chk.parent().parent().parent().find('.panel-body input');
					chkList.each(function(i, obj) {
						$(obj).prop('checked', true);
					});
				}
			}
	};
	$(function() {
		$('#saveBtn').click(function() {
			var _saveMsg = $('#saveMsg').empty();
			
			var _userId = $('#userId').val();
			
			var roleId = $('#roleId');
			var name = $('#name');
			if(JUtil.isEmpty(name.val())) {
				_saveMsg.append('请输入名称');
				name.focus();
				return;
			}
			
			var authIds = [];
			$('input[name="roleResIds"]:checked').each(function(i, obj) {
				authIds.push($(obj).val());
			});

			JUtil.ajax({
				eventId: 'saveBtn',
				url : '${webroot}/sysRole/f-json/save.shtml',
				data : {
					roleId: roleId.val(),
					name: name.val(),
					authIds: authIds.join(',')
				},
				success : function(json) {
					if (json.code === 0) {
						_saveMsg.attr('class', 'label label-success').append('保存成功');
						setTimeout(function() {
							parent.info.loadInfo();
							parent.dialog.close();
						}, 800);
					}
					else if (json.code === -1)
						_saveMsg.append(JUtil.msg.ajaxErr);
					else
						_saveMsg.append(json.message);
				}
			});
		});
	});
	</script>
</body>
</html>